<?php
/**
 * Created by PhpStorm.
 * User: geolo
 * Date: 2018/10/8
 * Time: 15:40
 */
namespace app\modules\mch\models;

use app\models\CharacterBlock;
use app\models\Store;
/**
 * @property CharacterBlock $model
 * @property Store $store
 */
class CharacterBlockEditForm extends Model
{
    public $model;
    public $wechat_app_id;
    public $store;

    public $name;
    public $name_e;
    public $url;

    public function rules()
    {
        return [
            [['name',], 'trim'],
            [['name', 'wechat_app_id',], 'required'],
            [['name_e','url','name'],'string'],
        ];
    }

    public function attributeLabels()
    {
        return [
            'name' => '名称',
            'name_e' => '英文名称',

        ];
    }

    public function save()
    {
        if (!$this->validate()) {
            return $this->getModelError();
        }
        $this->model->name = $this->name;
        $this->model->name_e = $this->name_e;
        $this->model->url = $this->url;
        $this->model->wechat_app_id = $this->wechat_app_id;
        if ($this->model->isNewRecord) {
//            $this->model->wechat_app_id = $this->store->id;
            $this->model->is_delete = 0;
        }
        if ($this->model->save())
            return [
                'code' => 0,
                'msg' => '保存成功',
            ];
        else
            return $this->getModelError($this->model);
    }
}